package at.fhj.itm11.forum.service.converter;

import java.util.ArrayList;
import java.util.List;

import at.fhj.itm11.forum.model.Icon;
import at.fhj.itm11.forum.model.Topic;
import at.fhj.itm11.forum.service.dtos.IconDTO;
import at.fhj.itm11.forum.service.dtos.TopicDTO;

public class TopicDTOConverter implements DTOConverter<TopicDTO, Topic> {
	
	private DTOConverter<IconDTO, Icon> iconDtoConverter = new IconDTOConverter();
	
	@Override
	public TopicDTO convertToDto(Topic topicEntity) {
		TopicDTO dto = new TopicDTO();

		dto.setId(topicEntity.getId());
		dto.setTitle(topicEntity.getTitle());
		dto.setDescription(topicEntity.getDescription());
		
		if(topicEntity.getIcon() != null) {
			dto.setIcon(iconDtoConverter.convertToDto(topicEntity.getIcon()));
		}

		return dto;
	}

	@Override
	public List<TopicDTO> convertToDto(List<Topic> topicEntities) {
		List<TopicDTO> topicDtoList = new ArrayList<TopicDTO>();

		for (Topic t : topicEntities) {
			topicDtoList.add(convertToDto(t));
		}

		return topicDtoList;
	}

	@Override
	public Topic convertToEntity(TopicDTO dto) {
		// TODO remove
		return null;
	}

}
